<template>
  <!-- 报告单元 -->
  <div id="smartScreen">
    <Breadcrumb content="智能屏" />
    <div class="bodyContent">
      <el-tabs type="border-card">
        <el-tab-pane label="基础字典">
          <Splitpanes class="area">
            <Pane size="50">
              <vxe-toolbar perfect>
                <template #buttons>
                  <vxe-input v-model="smartScreenForm.searchValue" type="search" clearable class="vxeInputSearch"
                    placeholder="关键字查询" @keyup="keyupEnter" @clear="getSmartScreenList"></vxe-input>
                  <vxe-button type="text" class="button-blue" icon="vxe-icon-refresh" content="刷新" :loading="showLoading"
                    @click="getSmartScreenList"></vxe-button>
                  <vxe-button type="text" icon="vxe-icon-delete" class="button-red" content="删除"
                    @click="handleDelete"></vxe-button>
                  <!-- <vxe-button type="text" class="button-blue" icon="vxe-icon-sort" content="数据同步" :loading="showLoading1" @click="pullPloyee"></vxe-button> -->
                </template>
              </vxe-toolbar>

              <div class="leftTable">
                <vxe-table ref="smartScreenTable" border="inner" align="left" class="mytable-scrollbar" :loading="showLoading"
                  height="auto" :data="smartScreenList" :expand-config="{ expandAll: true, reserve: true }"
                  @current-change="userRowClick" :row-config="{ isCurrent: true, isHover: true }" :keyboard-config="{
                    isArrow: true,
                    isTab: true,
                    isEdit: false
                  }" :edit-config="{ trigger: 'dblclick', mode: 'row', showStatus: true }" resizable show-overflow
                  keep-source>
                  <vxe-column type="checkbox" width="30"></vxe-column>
                  <vxe-column type="seq" title="#" width="30"></vxe-column>
                  <vxe-column field="smartCode" title="智能屏编号" width="90"></vxe-column>
                  <vxe-column field="smartName" title="智能屏名称"></vxe-column>
                  <vxe-column field="smartAddress" title="智能屏位置"></vxe-column>
                  <!-- <vxe-column field="status" title="智能屏状态"></vxe-column> -->
                  <vxe-column field="smartType" title="智能屏类型"></vxe-column>
                  <!-- <vxe-column field="smartAddress" title="智能屏位置"></vxe-column> -->
                  <vxe-column field="status" title="状态" width="80" align="center">
                    <template #default="{ row }">
                      <span class="table-tag" :class="`bg-${stateList[Number(row.status) - 1].color}`">{{
                        getIsStaticStatusDesc(row) }}</span>
                    </template>
                  </vxe-column>
                </vxe-table>
              </div>
            </Pane>

            <Pane size="50">
              <el-tabs type="border-card">
                <el-tab-pane label="基本信息">
                  <!-- 右侧基本信息 -->
                  <el-form ref="smartScreenFormRef" :model="smartScreenForm" label-width="110px" class="form-input-m baseForm"
                    v-loading="showLoading" inline-message :rules="rules">
                    <el-row :gutter="20">
                      <el-col :span="24">
                        <el-form-item label="智能屏唯一标识" prop="suid">
                          <el-input v-model="smartScreenForm.suid" placeholder="" clearable disabled
                            :style="{ width: 'var(--input-width, 60%)' }"></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="智能屏编码" prop="smartCode">
                          <el-input v-model="smartScreenForm.smartCode" placeholder="智能屏编码" clearable></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="智能屏名称" prop="smartName">
                          <el-input v-model="smartScreenForm.smartName" placeholder="智能屏名称" clearable></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="类型" prop="smartType">
                          <el-select @keyup="keyupEnter($event, 12)" ref="form12" v-model="smartScreenForm.smartType"
                            placeholder="请选择" style="width:200px">
                            <el-option v-for="item in smartTypeList" :key="item.titleCode" :label="item.titleName"
                              :value="item.titleCode" />
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="状态" prop="isEnabled">
                          <!--                          <el-switch v-model="smartScreenForm.isEnabled" inline-prompt active-text="是" inactive-text="否"
                                                      active-value="1" inactive-value="0"></el-switch>-->
                          <el-select v-model="smartScreenForm.status" clearable placeholder="Select" style="width: 180px">
                            <el-option v-for="(item, index) in stateList" :key="index" :value="`${item.value}`"
                              :label="item.label" />
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>

                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="智能屏位置" prop="smartAddress">
                          <el-input v-model="smartScreenForm.smartAddress" placeholder="智能屏位置" clearable></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="操作系统" prop="operatingSystem">
                          <el-select v-model="smartScreenForm.operatingSystem" clearable placeholder="操作系统"
                            style="width: 180px">
                            <el-option v-for="(item, index) in systemList" :key="index" :value="`${item.value}`"
                              :label="item.label" />
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <!-- <el-row :gutter="20">
                      <el-col :span="23">
                        <el-form-item label="操作命令" prop="command">
                          <el-input v-model="command" placeholder="请输入操作命令" clearable type="textarea"
                            :autosize="{ minHeight: 60, maxHeight: 300 }"></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row> -->
                    <vxe-toolbar perfect class="margin-top">
                      <template #buttons>
                        <span class="text-blue text-bold margin-left-sm">设备图片</span>
                      </template>
                    </vxe-toolbar>
                    <el-row :gutter="20">
                      <div style="width: clac(100% - 20px); border: 1px #eee solid">
                        <el-upload class="upload-demo" ref="fileUpload" :action="uploadUrl" :data="uploadData"
                          :headers="headers" multiple :limit="1" list-type="picture-card" :auto-upload="false"
                          v-model:file-list="fileList" :on-preview="handlePictureCardPreview"
                          :on-change="fileSelectChange" :before-upload="onbeforeUpload" :on-success="onSucessUpload"
                          :before-remove="fileRemove">
                          <el-icon>
                            <Plus />
                          </el-icon>
                        </el-upload>
                      </div>
                    </el-row>
                    <!-- <el-row :gutter="20">
                      <el-col :span="23">
                        <el-form-item label="是否启用" prop="isEnabled">
                          <el-switch v-model="smartScreenForm.isEnabled" inline-prompt active-text="是" inactive-text="否"
                            active-value="1" inactive-value="0"></el-switch>
                        </el-form-item>
                      </el-col>
                    </el-row> -->

                    <el-form-item class="form-footer">
                      <template #default>
                        <el-button type="primary" @click="addrptGroup">新建</el-button>
                        <el-button type="primary" v-loading="saveLoading" @click="save">保存</el-button>
                        <!-- <el-button type="default" @click="resetForm(currentUser)">重置</el-button> -->
                      </template>
                    </el-form-item>
                  </el-form>
                </el-tab-pane>
                <!-- <el-tab-pane label="功能菜单">
                  <Splitpanes>
                    <Pane size="50">
                      <vxe-toolbar perfect>
                        <template #buttons>
                          <vxe-button type="text" class="button-blue" icon="vxe-icon-refresh" content="刷新"
                            :loading="showLoading" @click="getSmartScreenList"></vxe-button>
                          <div class="msgDiv">双击项目移除对应关系</div>
                        </template>
                      </vxe-toolbar>
                      <div class="leftTable">
                        <vxe-table ref="rptVsBarCodeTable" border class="mytable-scrollbar" show-header-overflow
                          show-overflow align="center" :row-config="{ isCurrent: true, isHover: true }"
                          :data="machineVsFunList" :loading="showLoading" @cell-dblclick="deleteRptVsBarCode">
                          <vxe-column type="seq" title="序号" width="50"></vxe-column>
                          <vxe-column field="funcCode" title="功能编号"></vxe-column>
                          <vxe-column field="funcName" title="功能名称"></vxe-column>
                          <vxe-column field="title" title="标题"></vxe-column>
                        </vxe-table>
                      </div>
                    </Pane>
                    <Pane size="50">
                      <vxe-toolbar perfect>
                        <template #buttons>
                          <vxe-input v-model="functionSearchValue" type="search" clearable class="vxeInputSearch"
                            placeholder="关键字查询" @clear="getSmartScreenList" @keyup="getSmartScreenList"
                            @search-click="getSmartScreenList()"></vxe-input>
                          <vxe-button type="text" class="button-blue" icon="vxe-icon-refresh" content="刷新"
                            :loading="showLoading" @click="getSmartScreenList"></vxe-button>
                          <div class="msgDiv">双击项目添加对应关系</div>
                        </template>
                      </vxe-toolbar>
                      <div class="leftTable">
                        <vxe-table ref="barCodeTypeTable" border class="mytable-scrollbar" show-header-overflow
                          show-overflow align="center" :row-config="{ isCurrent: true, isHover: true }"
                          @cell-dblclick="barCodeRowClick" :data="functionDataList" :loading="showLoading">
                          <vxe-column type="seq" title="序号" width="30"></vxe-column>
                          <vxe-column type="seq" title="序号" width="50"></vxe-column>
                          <vxe-column field="funcCode" title="功能编号"></vxe-column>
                          <vxe-column field="funcName" title="功能名称"></vxe-column>
                          <vxe-column field="title" title="标题"></vxe-column>
                        </vxe-table>
                      </div>
                    </Pane>
                  </Splitpanes>
                </el-tab-pane> -->
                <el-tab-pane label="参数配置">
                  <el-form ref="smartParamRef" :model="smartParamForm" label-width="210px"
                    class="form-input-m baseForm" v-loading="showLoading" inline-message>

                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="主程序地址" prop="apiUrl" :style="{ width: 'var(--input-width, 100%)' }">
                          <el-input v-model="smartParamForm.apiUrl" placeholder="主程序地址" clearable></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="智能屏服务地址" prop="mainUrl">
                          <el-input v-model="smartParamForm.mainUrl" placeholder="智能屏服务地址" clearable></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <!-- <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="报表服务地址" prop="reportServiceUrl">
                          <el-input v-model="smartParamForm.reportServiceUrl" placeholder="报表服务地址" clearable></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="自动更新地址" prop="autoUpdateUrl">
                          <el-input v-model="smartParamForm.autoUpdateUrl" placeholder="自动更新地址" clearable></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row> -->

                    <!-- <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="读卡API地址" prop="transMedicalRecNoYsdApi">
                          <el-input v-model="smartParamForm.transMedicalRecNoYsdApi" placeholder="读卡API地址"
                            clearable></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="是否打印日志" prop="isLog">
                          <el-switch v-model="smartParamForm.isLog" inline-prompt active-text="是" inactive-text="否"
                            active-value="1" inactive-value="0"></el-switch>
                        </el-form-item>
                      </el-col>
                    </el-row> -->
                    <!-- <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="是否对接第三方智能屏打印" prop="isJoinThreed">
                          <el-switch v-model="smartParamForm.isJoinThreed" inline-prompt active-text="是"
                            inactive-text="否" active-value="1" inactive-value="0"></el-switch>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="是否自动打印" prop="autoExec">
                          <el-switch v-model="smartParamForm.autoExec" inline-prompt active-text="是" inactive-text="否"
                            active-value="1" inactive-value="0"></el-switch>
                        </el-form-item>
                      </el-col>
                    </el-row>

                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="是否开启卡号转换" prop="isTransCardNo">
                          <el-switch v-model="smartParamForm.isTransCardNo" inline-prompt active-text="是"
                            inactive-text="否" active-value="1" inactive-value="0"></el-switch>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="卡号转换方式" prop="transCardNoType">
                          <el-select @keyup="keyupEnter($event, 12)" ref="form12"
                            v-model="smartParamForm.transCardNoType" placeholder="请选择" style="width:200px">
                            <el-option v-for="item in TransCardNoTypeList" :key="item.value" :label="item.label"
                              :value="item.label" />
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row> -->

                    <!-- <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="打印完成是否自动关闭" prop="autoExit">
                          <el-switch v-model="smartParamForm.autoExit" inline-prompt active-text="是" inactive-text="否"
                            active-value="1" inactive-value="0"></el-switch>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="界面停留时间(秒)" prop="sleep">
                          <el-input v-model="smartParamForm.sleep" placeholder="界面停留时间" clearable></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="检验科打印后允许智能屏打印" prop="reprint">
                          <el-switch v-model="smartParamForm.reprint" inline-prompt active-text="是" inactive-text="否"
                            active-value="1" inactive-value="0"></el-switch>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="号码截取方式:R  L  M" prop="transCodeType">
                          <el-select v-model="smartParamForm.transCodeType" clearable placeholder="Select"
                            style="width: 180px">
                            <el-option v-for="(item, index) in transCodeTypeList" :key="index" :value="`${item.value}`"
                              :label="item.label" />
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row> -->
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="智能屏配置" prop="transCodeLen">
                          <el-input v-model="smartParamForm.transCodeLen" placeholder="配置1" clearable></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="智能屏配置" prop="transCodeStr">
                          <el-input v-model="smartParamForm.transCodeStr" placeholder="智能屏配置" clearable></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="通知内容" prop="days">
                          <el-input v-model="smartParamForm.days" placeholder="通知内容" clearable></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="医院/智能屏显示名称" prop="showName">
                          <el-input v-model="smartParamForm.showName" placeholder="智能屏显示名称" clearable></el-input>
                        </el-form-item>
                      </el-col>
                      <!-- <el-col :span="12">
                        <el-form-item label="打印病人类型" prop="patType">
                          <el-select v-model="smartParamForm.patType" clearable placeholder="Select" style="width: 180px">
                            <el-option v-for="(item, index) in patTypeList" :key="index" :value="`${item.value}`"
                              :label="item.label" />
                          </el-select>
                        </el-form-item>
                      </el-col> -->
                    </el-row>
                    <!-- <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="是否保持窗体最顶端显示" prop="isTopMost">
                          <el-switch v-model="smartParamForm.isTopMost" inline-prompt active-text="是" inactive-text="否"
                            active-value="1" inactive-value="0"></el-switch>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="医院/智能屏显示名称" prop="showName">
                          <el-input v-model="smartParamForm.showName" placeholder="智能屏显示名称" clearable></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row> -->
                    <el-form-item class="form-footer">
                      <template #default>
                        <!-- <el-button type="primary" @click="addParam">新建</el-button> -->
                        <el-button type="primary" v-loading="saveLoading" @click="saveParam">保存</el-button>
                      </template>
                    </el-form-item>
                  </el-form>
                </el-tab-pane>
              </el-tabs>
            </Pane>
          </Splitpanes>
        </el-tab-pane>
      </el-tabs>
      <!-- 大图预览 -->
      <el-dialog v-model="dialogVisibleImg">
        <img :src="dialogImageUrl" alt="" />
      </el-dialog>
    </div>
  </div>
</template>

<script setup lang="ts">
// 引入组件区 ==========
import Breadcrumb from '@/components/Breadcrumb.vue';
import { ref, reactive, getCurrentInstance, onMounted, computed } from 'vue';
import { IsEmpty, pageSizes } from '../../../utils/common'; //导入工具函数
import { Splitpanes, Pane } from 'splitpanes';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage'; //提示信息
import { funBdsJsResult } from '@/utils/Expression'; //函数公式
import { AppStore } from '@/stores/store';
import { isEmpty } from 'lodash';
import { v4 as uuidv4 } from 'uuid';

// 全局变量定义区 ==========
let { proxy }: any = getCurrentInstance();
let store = AppStore();

const orgList = store.userInfo.orgList;
// 加载状态
let showLoading = ref(false); //左侧表格加载+上方刷新按钮+右侧表单+右侧详情
let saveLoading = ref(false); //保存
let smartScreenTable = ref(null); //table表格
let smartScreenList: any = reactive([]); //table列表数据
let machineVsFunList: any = reactive([]); //table列表数据
let functionDataList: any = reactive([]); //table列表数据
let currentUser = reactive({}); //当前智能屏
let smartScreenForm = reactive({
  id: '',
  smartCode: '',
  smartName: '',
  status: '',
  smartType: '',
  isEnabled: '1',
  searchValue: '',
  smartAddress: '',
  suid: '',
  operatingSystem: 'Windows'
});

const rules = reactive<VxeFormPropTypes.Rules>({
  smartName: [{ required: true, message: '请输入名称' }],
  smartCode: [{ required: true, message: '请输入编号' }]
});
const stateList = ref([
  {
    code: 1,
    value: 1,
    name: '运行中',
    label: '运行中',
    color: 'green'
  },
  {
    code: 2,
    value: 2,
    name: '闲置',
    label: '闲置',
    color: 'orange'
  },
  {
    code: 3,
    value: 3,
    name: '故障',
    label: '故障',
    color: 'red'
  }
])

const patTypeList = ref([
  {
    value: 0,
    label: '全部',
  },
  {
    value: 1,
    label: '门诊',
  },
  {
    value: 2,
    label: '急诊',
  },
  {
    value: 3,
    label: '住院',
  },
  {
    value: 4,
    label: '体检',
  }
])


let uploadUrl = (window as any).apiUrl.VITE_SERVER_URL + '/smart/screen/uploadSelfImage';
let uploadData = reactive({
  selfId: ''
});
let headers = {
  Authorization: 'Bearer ' + localStorage.getItem('token')
};
let fileList: any = reactive([]);
let dialogVisibleImg = ref(false); //图片查看
let dialogImageUrl = ref(''); //放大图片地址
let uploadArrFile: any = reactive([]);


let smartParamForm = reactive({
  apiUrl: 'http://localhost:5041',
  mainUrl: 'http://localhost:8080/#/',
  reportServiceUrl: 'http://server.ysddev.cn:11012',
  autoUpdateUrl: 'http://server.ysddev.cn:44391/AutoUpdate.xml',
  transMedicalRecNoYsdApi: 'http://localhost:5041/lab/hisReq/getIdCardByBarcode',
  isLog: '1',
  isJoinThreed: '',
  isTransCardNo: '',
  transCardNoType: '',
  updateRate: '',
  specificPrinterList: '',
  serviceUri: '',
  autoExec: '1',
  autoExit: '1',
  sleep: '',
  tts: '',
  ttscomp: '',
  ttsspeaker: '',
  ttsvolume: '',
  ttsrate: '',
  reprint: '',
  exepath: '',
  textpath: '',
  transCodeType: 'L',
  transCodeLen: '64',
  transCodeStr: '1',
  days: '365',
  patType: '0',
  isEnableWtFilter: '',
  isTopMost: '',
  showName: ''
})

let transCodeTypeList = ref([{
  value: 'L',
  label: 'L'
},
{
  value: 'M',
  label: 'M'
},
{
  value: 'R',
  label: 'R'
}]);



let TransCardNoTypeList = ref([{
  value: 'sql',
  label: 'SQL'
},
{
  value: 'api',
  label: '接口'
}]);

let systemList = ref([{
  value: 'Windows',
  label: 'Windows'
},
{
  value: 'macOS',
  label: 'macOS'
},
{
  value: 'Linux',
  label: 'Linux'
}]);

let sltPurpose: any = ref({});
let functionSearchValue = ref('')

const smartScreenFormRef = ref();

// let command = ref('');

// 把 command 变成计算属性，实现自动更新
const command = computed(() => {
  console.log('ooookkkkk', smartScreenForm.operatingSystem);
  switch (smartScreenForm.operatingSystem) {
    case 'Windows':
      return `reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" 
        /v "MyApp" 
        /t REG_SZ 
        /d "\\"C:\\Path\\To\\YourApp.exe\\"" 
        /f`;
    case 'Linux':
      return `sudo nano /etc/rc.local  
      /path/to/your/app &`;
    case 'macOS':
      return `osascript -e 'tell application "System Events" 
                      to make login item at end 
                      with properties {path:"/Applications/MyApp.app", hidden:false}'`;
    default:
      return '';
  }
});

// 页面加载时更新
onMounted(() => {
  getSmartScreenList(); //加载列表
  getMachineTypeList();
});

function getIsStaticStatusDesc(row: any) {
  console.log('row', row)
  if (isEmpty(row) || isEmpty(row.status)) {
    return '';
  }
  for (const item of stateList.value) {
    if (row.status == item.value) {
      return item.name;
    }
  }
}
function getIsStaticTagType(row) {
  if (row.isEnabled == 1) {
    return 'success';
  } else if (row.isEnabled == 0) {
    return 'danger';
  }
}

// 删除数据
function deleteRptVsBarCode({ row }: any) {
  const url = '/self/machineFunction/deleteMachineFunction';
  proxy.$http
    .post(url, {
      id: row.id
    })
    .then((res: any) => {
      //获取右侧数据
      getFunctionDataList(smartScreenForm.smartCode);
      //获取中间数据
      findBarcodeList(smartScreenForm.suid);
      VxeMessage(res.status.msg, VxeNotifyType.success);
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

//查询搜索报告单元列表
function getSmartScreenList() {
  showLoading.value = true;
  smartScreenList.length = 0;
  const url = '/smart/screen/findSmartScreenList';
  let obj = {
    keyWords: smartScreenForm.searchValue
  };
  proxy.$http
    .get(url, { params: obj })
    .then((res: any) => {
      smartScreenList.push(...res.data);
      if (smartScreenList.length > 0) {
        const kn = smartScreenList.find((k) => k.id == sltPurpose.value.id);
        if (isEmpty(kn)) {
          userRowClick({ row: smartScreenList[0] });
        } else {
          userRowClick({ row: kn });
        }
      }
      showLoading.value = false;
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
  //showLoading.value = true;
}


const smartTypeList = reactive([]);

//查询
function getMachineTypeList() {
  showLoading.value = true;
  smartTypeList.length = 0;
  const url = '/self/machine/type/findMachineTypeList';
  let obj = {
    keyWords: ''
  };
  proxy.$http
    .get(url, { params: obj })
    .then((res: any) => {
      smartTypeList.push(...res.data);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
  //showLoading.value = true;
}


// 回车查询
function keyupEnter(e: any) {
  if (e.$event.code == 'Enter') {
    getSmartScreenList();
  }
}

// 重置
function resetForm(row: any) {
  smartScreenForm.id = '';
  smartScreenForm.smartCode = '';
  smartScreenForm.smartName = '';
  smartScreenForm.status = '1';
  smartScreenForm.smartType = '';
  smartScreenForm.isEnabled = '1';
  smartScreenForm.smartAddress = '';
  smartScreenForm.operatingSystem = 'Windows';
}

// 点击当前行// 行点击事件(需要调试)
function userRowClick({ row }: any) {
  fileList.length = 0;
  if (isEmpty(row)) {
    currentUser = {} as any;
    return;
  }

  (proxy.$refs.smartScreenTable as any).setCurrentRow(row);

  Object.assign(smartScreenForm, row);
  Object.assign(smartParamForm, row);
  if (!isEmpty(row.imagePath)) {
    fileList.push({
      id: row.id,
      url: (window as any).apiUrl.VITE_SERVER_URL + row.imagePath
    });
  }
  //获取右侧数据
  getFunctionDataList(smartScreenForm.suid);
  //获取中间数据
  findBarcodeList(smartScreenForm.suid);


}

function getFunctionDataList(suid: string) {
  functionDataList.length = 0;
  let obj = {
    keyWords: functionSearchValue.value,
    suid: suid
  };
  const url = '/self/machineFunction/findFunction';
  proxy.$http
    .get(url, { params: obj })
    .then((res: any) => {
      functionDataList.push(...res.data);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}


// 新建报告单元
function addrptGroup() {
  clearForm();
  (proxy.$refs.smartScreenTable as any).clearCurrentRow();
}


// 保存分管类别
function save(formName: any) {
  smartScreenFormRef.value?.validate((valid: any) => {
    if (!valid) {
      VxeMessage('校验表单失败', VxeNotifyType.error);
      return false;
    }
    let url = '/smart/screen/savaOrUpdateSmartScreen';
    proxy.$http
      .post(url, smartScreenForm)
      .then((res: any) => {
        let $form = proxy.$refs.fileUpload;
        $form.submit();
        proxy.$nextTick(() => {
          VxeMessage(res.status.msg, VxeNotifyType.success);
          getSmartScreenList();
        })
      })
      .catch((err: any) => {
        VxeMessage(err, VxeNotifyType.error);
      });
  });
}


// 保存分管类别
function saveParam(formName: any) {
  let url = '/smart/screen/savaOrUpdateSmartScreen';
  proxy.$http
    .post(url, smartParamForm)
    .then((res: any) => {
      let $form = proxy.$refs.fileUpload;
      $form.submit();
      proxy.$nextTick(() => {
        VxeMessage(res.status.msg, VxeNotifyType.success);
        getSmartScreenList();
      })
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

// 清空右侧表单
function clearForm() {
  smartScreenForm.id = '';
  smartScreenForm.smartCode = '';
  smartScreenForm.smartName = '';
  smartScreenForm.status = '1';
  smartScreenForm.smartType = '';
  smartScreenForm.isEnabled = '1';
  smartScreenForm.smartAddress = '';
  smartScreenForm.suid = uuidv4();
  smartScreenForm.operatingSystem = 'Windows';
}


// 新建报告单元
function addParam() {
  clearParamForm();
}

// 清空右侧表单
function clearParamForm() {
  smartParamForm.apiUrl = 'http://localhost:5041';
  smartParamForm.mainUrl = 'http://localhost:8080/#/';
  smartParamForm.reportServiceUrl = 'http://server.ysddev.cn:11012';
  smartParamForm.autoUpdateUrl = 'http://server.ysddev.cn:44391/AutoUpdate.xml';
  smartParamForm.transMedicalRecNoYsdApi = 'http://localhost:5041/lab/hisReq/getIdCardByBarcode';
  smartParamForm.isLog = '1';
  smartParamForm.isJoinThreed = '';
  smartParamForm.isTransCardNo = '';
  smartParamForm.transCardNoType = '';
  smartParamForm.autoExec = '1';
  smartParamForm.autoExit = '1';
  smartParamForm.sleep = '10';
  smartParamForm.reprint = '';
  smartParamForm.transCodeType = 'L';
  smartParamForm.transCodeLen = '64';
  smartParamForm.transCodeStr = '1';
  smartParamForm.days = '365';
  smartParamForm.patType = '0';
  smartParamForm.isTopMost = '';
  smartParamForm.showName = '';
}


// 删除数据
function handleDelete() {
  const selectRows = (proxy.$refs.smartScreenTable as any).getCheckboxRecords();

  if (selectRows.length <= 0) {
    VxeMessage('请选择需要删除的数据', VxeNotifyType.warning);
    return;
  }
  const url = '/smart/screen/deleteSmartScreen';
  proxy.$http
    .post(url, selectRows)
    .then((res: any) => {
      getSmartScreenList();
      VxeMessage(res.status.msg, VxeNotifyType.success);
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

function barCodeRowClick({ row }: any) {
  const url = '/self/machineFunction/addMachineFunction';
  let data = {
    smartCode: smartScreenForm.smartCode,
    funcCode: row.funcCode,
    suid: smartScreenForm.suid
  };
  proxy.$http
    .post(url, data)
    .then((res: any) => {
      findBarcodeList(smartScreenForm.suid);
      getFunctionDataList(smartScreenForm.suid);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}
// 获取中间的报告单元信息
function findBarcodeList(suid: string) {
  machineVsFunList.length = 0;
  const url = '/self/machineFunction/findMachineFunction/' + suid;
  proxy.$http
    .get(url)
    .then((res: any) => {
      machineVsFunList.push(...res.data);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}

//预览
// function openNewTab() {
//   // 使用Vue Router
//   // const router = useRouter()
//   // const routeData = router.resolve({ name: 'target-page' })
//   // window.open(routeData.href, '_blank')

//   // 或者直接使用URL
//   //window.open('http://localhost:8080/', '_blank')

//   const data = {
//     url: '/invHome',
//     orderStatus: '5'
//   };
//   proxy.$router.push({ path: '/slef/testReport', query: data });

// }

// 上传文件改变事件
function fileSelectChange(file, fileList) {
  uploadArrFile.push(file.raw);
}

// 上传文件改变事件
function onbeforeUpload(file) {
  if (IsEmpty(smartScreenForm.id)) {
    return false;
  }
  uploadData.selfId = smartScreenForm.id;
}


function onSucessUpload(respone, file, fileList) {
  console.log('respone', respone);
  if (respone && respone.status.code === 1) {
    file.id = respone.data.id;
    file.url = (window as any).apiUrl.VITE_SERVER_URL + respone.data.imagePath;
  }
}

// 删除上传文件
function fileRemove(file) {
  if (IsEmpty(file.id)) {
    const index = uploadArrFile.indexOf(file);
    if (index > -1) {
      uploadArrFile.splice(index, 1);
    }
  } else if (file.status === 'success') {
    const url = '/smart/screen/deleteFileById';
    proxy.$http
      .get(url, { params: { id: file.id, filePath: file.url } })
      .then((res: any) => {
        const index = uploadArrFile.indexOf(file);
        if (index > -1) {
          uploadArrFile.splice(index, 1);
        }
        getSmartScreenList();
        VxeMessage('删除成功', VxeNotifyType.success);
      })
      .catch((err: any) => {
        VxeMessage('删除失败', VxeNotifyType.error);
      });
  }
}

// 大图查看
function handlePictureCardPreview(file) {
  dialogImageUrl.value = file.url;
  dialogVisibleImg.value = true;
}


</script>

<style lang="scss" scoped>
#smartScreen {
  height: 100%;

  .bodyContent {
    height: calc(100% - 60px);

    :deep(.el-tabs) {
      height: 100%;

      .el-tabs__content {
        height: calc(100% - 39px);
        padding: 0;

        .el-tab-pane {
          height: 100%;
        }
      }
    }

    .area {
      background-color: $base-white;

      // 附加按钮间距
      .button-blue,
      .button-red {
        margin: 5px 0 5px 5px;
      }

      .leftTable {
        height: calc(100% - 39px);

        :deep(.vxe-table--render-wrapper) {
          height: 100%;

          .vxe-table--main-wrapper {
            height: 100%;

            .vxe-table--body-wrapper {
              height: calc(100% - 26px) !important;
            }
          }
        }

        :deep(.vxe-table--render-default) {
          height: calc(100% - 36px) !important;
        }
      }

      // 右侧基本信息表单
      .baseForm {
        .el-row {
          margin-left: 0 !important;
          margin-right: 0 !important;
        }

        .form-footer {
          :deep(.el-form-item__content) {
            margin-left: 120px !important;
          }
        }

        .el-form-item--large {
          margin-bottom: 10px;
        }

        .el-radio {
          margin-right: 20px;
        }
      }

      .msgDiv {
        margin-left: 5px;
        color: rgb(180, 28, 28);
      }

      .leftTable {
        height: calc(100% - 39px);

        .table-tag {
          display: inline-block;
          width: 60px;
          text-align: center;
        }

        // :deep(.vxe-table--render-wrapper) {
        //   height: 100%;

        //   .vxe-table--main-wrapper {
        //     height: 100%;

        //     .vxe-table--body-wrapper {
        //       height: calc(100% - 26px) !important;
        //     }
        //   }
        // }

        // :deep(.vxe-table--render-default) {
        //   height: calc(100% - 36px) !important;
        // }
      }

      .el-tabs--border-card {
        border: none;
        height: 100%;

        :deep(.el-tabs__content) {
          height: calc(100% - 39px - 20px);
          padding: 10px;

          .el-tab-pane {
            height: 100%;
          }
        }
      }

      // tab报告单元仪器

      .rptGroupInstrTable {
        height: calc(100% - 24px - 10px);
      }

      .el-radio {
        margin-right: 10px;
      }
    }
  }
}
</style>
